<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions">

<h:head>
</h:head>
<h:body>
	<h1>Data table filtering</h1>

	<h:form>
		<p:dataTable 
			id="tabela" 
			emptyMessage="Nenhuma vinculação de loja para empréstimo encontrada"
			filteredValue="#{vinculacaoBean.filteredVinculacoes}"
			paginator="true" 
			paginatorPosition="bottom"
			rows="10" 
			rowsPerPageTemplate="5,10,15"
			rowKey="#{vinculacao.id}"
			selection="#{vinculacaoBean.vinculacoesSelecionadas}"
			sortBy="produto.nome" 
			value="#{vinculacaoBean.vinculacoes}"
			var="vinculacao"
			widgetVar="tabelaVinculacao">
						
			<p:column selectionMode="multiple" style="width:2%"/>			
			
			<p:column headerText="Código">
				<h:outputText value="#{vinculacao.id}" />
			</p:column>

			<p:column filterBy="#{vinculacao.produto.nome}"
				headerText="Produto" 
				filterMatchMode="contains" sortBy="#{vinculacao.produto.nome}">
				<f:facet name="filter">
					<p:selectOneMenu onchange="PF('tabelaVinculacao').filter()">
						<f:selectItems value="#{vinculacaoBean.produtos}" />
					</p:selectOneMenu>
				</f:facet>
				<h:outputText value="#{vinculacao.produto.nome}" />
			</p:column>

			<p:column filterBy="#{vinculacao.convenio.nome}"
				headerText="Convênio" filterOptions="#{vinculacaoBean.convenios}"
				filterMatchMode="exact" sortBy="#{vinculacao.convenio.nome}">
				<f:facet name="filter">
					<p:selectOneMenu onchange="PF('tabelaVinculacao').filter()">
						<f:selectItems value="#{vinculacaoBean.convenios}" />
					</p:selectOneMenu>
				</f:facet>
				<h:outputText value="#{vinculacao.convenio.nome}" />
			</p:column>

			<p:column filterBy="#{vinculacao.tabelaTaxa.nome}"
				headerText="Tabelas de taxas e comissões"
				filterOptions="#{vinculacaoBean.tabelasTaxas}"
				filterMatchMode="exact" sortBy="#{vinculacao.tabelaTaxa.nome}">
				<f:facet name="filter">
					<p:selectOneMenu onchange="PF('tabelaVinculacao').filter()">
						<f:selectItems value="#{vinculacaoBean.tabelasTaxas}" />
					</p:selectOneMenu>
				</f:facet>
				<h:outputText value="#{vinculacao.tabelaTaxa.nome}" />
			</p:column>

			<p:column filterBy="#{vinculacao.tabelaTC.codTC}"
				headerText="Tabela de TC"
				filterOptions="#{vinculacaoBean.tabelasTC}" filterMatchMode="exact"
				sortBy="#{vinculacao.tabelaTC.codTC}">
				<f:facet name="filter">
					<p:selectOneMenu onchange="PF('tabelaVinculacao').filter()">
						<f:selectItems value="#{vinculacaoBean.tabelasTC}" />
					</p:selectOneMenu>
				</f:facet>
				<h:outputText value="TC #{vinculacao.tabelaTC.codTC}" />
			</p:column>

		</p:dataTable>
		
		<br/> <br/>
		
		<p:dataTable 
			id="tabelaLoja" 
			emptyMessage="Nenhuma loja encontrada"
			filteredValue="#{vinculacaoBean.filteredLojas}"
			paginator="true" 
			paginatorPosition="bottom"
			rows="10" 
			rowsPerPageTemplate="5,10,15"
			rowKey="#{loja.id}"
			selection="#{vinculacaoBean.lojasSelecionadas}"
			sortBy="nomeFantasia" 
			value="#{vinculacaoBean.lojas}"
			var="loja"
			widgetVar="tabelaLojas">
						
			<p:column selectionMode="multiple" style="width:2%"/>

			<p:column filterBy="#{loja.id}" headerText="Código"
				filterMatchMode="contains" sortBy="#{loja.id}">
				<h:outputText value="#{loja.id}" />
			</p:column>

			<p:column filterBy="#{loja.nomeFantasia}" headerText="Loja"
				filterMatchMode="contains" sortBy="#{loja.nomeFantasia}">
				<h:outputText value="#{loja.nomeFantasia}" />
			</p:column>

		</p:dataTable>
	</h:form>

</h:body>
</html>